// pages/reserve/index.js
const App = getApp();
Page({
  /**
   * 组件的属性列表
   */

  /**
   * 组件的初始数据
   */
  data: {
    detailList:{},
    items: [
      {value: '10', name: '余额支付'},
      {value: '20', name: '微信支付', checked: 'true'}
    ],
    payType:'20'
  },
  onShow(){
    this.setData({
      detailList:wx.getStorageSync('detailList')
    })
    
  },
  /**
   * 组件的方法列表
   */
  // methods: {

    radioChange(e) {
      console.log(e.detail.value)

      const items = this.data.items
      for (let i = 0, len = items.length; i < len; ++i) {
        items[i].checked = items[i].value === e.detail.value
      }
      this.setData({
        items,
        payType:e.detail.value
      })
    },
    reserve(){
      let _this = this;
      App._get('card/pay', {
        card_id:wx.getStorageSync('card_id'),
        payType:_this.data.payType
      }, function (result) {
        console.log(result)

        if(_this.data.payType=='20'){
          App.wxPayment({
            payment: result.data.payment,
            success() {
               wx.navigateTo({
                  url: '/pages/category/index',
                })
            },
            fail() {
              App.showError(result.msg.error);
            },
          });
        }
        if(_this.data.payType=='10'){
          App.showSuccess(result.msg.success, () => {
             wx.navigateTo({
              url: '/pages/category/index',
            })
          });
        }
        // _this.setData({
        //   list: result.data.data
        // });
      });
     
    }
    
  // }
})
